﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using BCDto.Common.Service.WebsiteServiceItem;
using BCDto.Common.Service.WebsiteServiceType;
using BCService.Common.Service.WebsiteServiceItem;
using BCService.Common.Service.WebsiteServiceType;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace BCTMSRESTful.Controllers.Anonymous
{
    [Route("api/v1/[controller]")]
    [ApiController]
    public class ServiceController : BCTMSRESTfulAPIController
    {
        private readonly IWebsiteServiceTypeService websiteServiceTypeService;
        private readonly IWebsiteServiceItemService websiteServiceItemService;

        public ServiceController(IWebsiteServiceTypeService websiteServiceTypeService, IWebsiteServiceItemService websiteServiceItemService)
        {
            this.websiteServiceTypeService = websiteServiceTypeService;
            this.websiteServiceItemService = websiteServiceItemService;
        }

        /// <summary>
        /// 获取官网服务类型列表。
        /// </summary>
        /// <response code="200">返回官网服务类型列表</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<WebsiteServiceTypeDto>), 200)]
        [AllowAnonymous]
        public IActionResult Types()
        {
            return this.Ok(this.websiteServiceTypeService.GetList());
        }

        /// <summary>
        /// 获取官网服务项目列表。
        /// </summary>
        /// <param name="websiteServiceTypeId">服务类型Id</param>
        /// <response code="200">返回官网服务项目列表</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(IEnumerable<WebsiteServiceItemDto>), 200)]
        [AllowAnonymous]
        public IActionResult Get([FromQuery(Name = "type_id")]int? websiteServiceTypeId)
        {
            return this.Ok(this.websiteServiceItemService.GetList(websiteServiceTypeId));
        }

        /// <summary>
        /// 获取官网所有服务项目列表。
        /// </summary>
        /// <response code="200">返回官网所有服务项目列表</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<WebsiteServiceViewDto>), 200)]
        [AllowAnonymous]
        public IActionResult All()
        {
            return this.Ok(this.websiteServiceItemService.GetAllList());
        }
    }
}
